package com.majsubtense.core.components;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;

import java.io.IOException;
import java.net.URL;

public abstract class UI extends Component {
    public static final ComponentType<UI> ANY;
    protected Pane pane;
    protected Scene scene;

    public UI(ComponentType<? extends Component> componentType) {
        super(componentType);
    }

    public void loadFXML(String fxmlSourcePath) {
        try {
            URL resource = getClass().getResource(fxmlSourcePath);
            assert resource != null : "ui load failed!";

            Parent root = FXMLLoader.load(resource);
            scene = new Scene(root, 600, 400);
        } catch (IOException exp) {
            exp.printStackTrace();
        }
    }

    public void showEffect(String text, float[] position) {

    }

    public abstract void attach();

    public abstract void update();

    public abstract void detach();

    public Scene getScene() {
        return scene;
    }

    public Pane getPane() {
        return pane;
    }

    static {
        ANY = new ComponentType<>(ComponentType.ROOT, "UI");
    }
}
